﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfUMLTry1.Model.Fight
{
    public enum AttackTypes { Physical, Magic }

    public class AttackStruct
    {
        #region Fields
        //index - element : 0 - Fizikai, 1 - Magic (később bővíthető vágás/ütés ; villám/föld)
        private static readonly Int32 NUM_OF_ATTACK_TYPES = 2;
        private List<Int32> damages;

        //public
        public Boolean reflectedDamage;
        #endregion

        public AttackStruct()
        {
            damages = new List<Int32>(NUM_OF_ATTACK_TYPES);
            for (int i = 0; i < NUM_OF_ATTACK_TYPES; ++i)
                damages.Add(0);
            reflectedDamage = false;
        }

        private void SetAttackValue(Int32 type, Int32 val)
        {
            if (type < NUM_OF_ATTACK_TYPES)
            {
                damages[type] = val;
            }
            else
                throw new InFightException("Invalid Attack Type");
        }
        public void SetAttackValue(AttackTypes type, Int32 val)
        {
            SetAttackValue((Int32)type, val);
        }

        private void IncreaseAttackValue(Int32 type, Int32 val)
        {
            if (type < NUM_OF_ATTACK_TYPES)
            {
                damages[type] += val;
            }
            else
                throw new InFightException("Invalid Attack Type");
        }
        public void IncreaseAttackValue(AttackTypes type, Int32 val)
        {
            IncreaseAttackValue((Int32)type, val);
        }

        public void DecreaseAttackValue(AttackTypes type, Int32 val)
        {
            IncreaseAttackValue((Int32)type, val * (-1));
        }

        public Int32 PhisDMGSum()
        {
            return damages[0];
        }
        public Int32 MagicDMGSum()
        {
            return damages[1];
        }
        public Int32 AllDMGSum()
        {
            Int32 s = 0;
            foreach (Int32 i in damages)
                s += i;
            return s;
        }
        public Int32 SpecificDMG(AttackTypes type)
        {
            if ((Int32)type < NUM_OF_ATTACK_TYPES)
            {
                return damages[(Int32)type];
            }
            else
                throw new InFightException("Invalid Attack Type - GetSpecDMG val");
        }

        public static AttackStruct operator *(AttackStruct as1, AttackStruct as2)
        {
            AttackStruct as3 = new AttackStruct();
            for(int i = 0; i < NUM_OF_ATTACK_TYPES; ++i)
                as3.damages[i] = as1.damages[i] * as2.damages[i] / 100;
            return as3;
        }

        public static AttackStruct operator +(AttackStruct as1, AttackStruct as2)
        {
            AttackStruct as3 = new AttackStruct();
            for (int i = 0; i < NUM_OF_ATTACK_TYPES; ++i)
                as3.damages[i] = as1.damages[i] + as2.damages[i];
            return as3;
        }
    }
}
